import numpy as np
from scipy.io import wavfile

# 设置参数
sample_rate = 44100  # 采样率
duration = 0.1  # 持续时间（秒）
frequency = 1000  # 频率（Hz）

# 生成时间序列
t = np.linspace(0, duration, int(sample_rate * duration), False)

# 生成正弦波
audio = np.sin(2 * np.pi * frequency * t)

# 添加淡入淡出效果
fade_duration = 0.02  # 20ms的淡入淡出
fade_length = int(fade_duration * sample_rate)
fade_in = np.linspace(0, 1, fade_length)
fade_out = np.linspace(1, 0, fade_length)

audio[:fade_length] *= fade_in
audio[-fade_length:] *= fade_out

# 归一化到16位整数范围
audio = np.int16(audio * 32767)

# 保存为WAV文件
wavfile.write('../resources/audio/turn.wav', sample_rate, audio)